﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;
using Autofac.Core;
using Winter.Core.DAL;
using Winter.Core.Service;
using Winter.Core.Infrastructure.DependencyManagement;
using Winter.WcfService.Base;
using Winter.WcfService.Interface;
using Winter.WcfService;

namespace Winter.Web.Mvc.Infrastructure
{
    internal class DependencyConfigure : IDependencyRegistrar
    {
        public static String GetConnectionString()
        {
            return System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        }

        public static void Initialize()
        {
            var builder = new ContainerBuilder();
            DependencyResolver.SetResolver(new Dependency());
        }

        public void Register(ContainerBuilder builder, Core.Infrastructure.ITypeFinder typeFinder)
        {

            //deal with your dependencies here
            builder.Register<IDbContext>(c => new DataContext(GetConnectionString()));

            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>));

            builder.RegisterGeneric(typeof(GenericManager<,>)).As(typeof(IGenericManager<,>)).PropertiesAutowired();
            builder.RegisterType<ProductManager>().As<IProductManager>().PropertiesAutowired();

            builder.RegisterGeneric(typeof(GenericWcfService<,>)).As(typeof(IGenericWcfService<,>)).PropertiesAutowired();
            builder.RegisterType<ProductService>().As<IProductService>().PropertiesAutowired();
        }

        public int Order
        {
            get { return 0; }
        }
    }
}